<?php
error_reporting(0);
require_once('lib.php');
session_start();
if(login()){
	$log = true;
}else{
	$log = false;
}

if($log){
	$d = $_GET['edoc_id'];
	$rr = getPG("select * from view_edoc_pdf where edoc_id=$d;");
	if(isset($rr[0]) && (canLoadPDF($rr[0]['edoc_id']))){
		$pdf = $rr[0]['pdf'];
		$pdf_name = $rr[0]['pdf_name'];
		$pdf_type = $rr[0]['pdf_type'];

        $pdf_dat = pg_unescape_bytea($pdf);

		header('Content-Type: '.$pdf_type);
		header('Content-Length: '.strlen($pdf_dat));
		header('Content-disposition: inline; filename="'.$pdf_name.'"');

		echo $pdf_dat;
	}else echo 	"Sorry ! ....";

}else{
	echo "Sorry ! ....";
}
?>
